import { uploadUrl } from "@/pages/api/report/helperOrderp.js";
import { getByOrdersId, updatechutu } from "@/pages/api/report/orderp.js";
import {
  getOrderDetail,
  getTakeTask,
  postOrderHandle,
  orgByNodeId,
  allocate,
  allocatedo,
  postWithdraw,
  postOrderAudit,
  postCheck,
  getMyList,
  postCloseOrder,
  postBackStep,
  cancelTask,
  allocatepostWithdraw,
  allocatepostCloseOrder,
  getPersonListApi,
  getWorkOrderLogs,
} from "@/pages/api/orderp/orderp.js";
import { mapState, mapMutations } from "vuex";
export default {
  computed: {
    ...mapState(["userInfo", "path"]),
    inputed() {
      if (this.checkop == 1) {
        return false;
      } else {
        return true;
      }
    },
  },
  methods: {
    ...mapMutations("mdOrder", [
      "setOrderIdSp",
      "setInfoOrder",
      "setInfoRecords",
    ]),
    ...mapMutations("mdApprove", ["setInfoApprove", "setLicenseData"]),
    // 选择部门弹窗
    choseDep() {
      this.departmentShow = true;
    },
    // 更新部门
    updateDep(val) {
      this.departmentList.forEach((item, index) => {
        if (index == val) {
          this.detailmsg.competentDepartment = item.name;
        }
      });
      console.log(this.detailmsg.competentDepartment);
    },
    //转发
    forward() {
      this.personShow = true;
    },
    // 工单转发成功
    appointTaskSuccess() {
      uni.$emit("updatelist", 10);
      this.$refs.uToast.show(
        {
          title: "转发成功",
          type: "success",
          url: "/pages/index/approval/index",
        },
        500
      );
    },
    appointTaskCancel() {
      this.personShow = false;
    },
    //预览图片
    previewPic(item) {
      console.log("图片操作事件", item);
      let arr = [];
      arr.push(item);
      console.log("图片预览", arr);
      uni.previewImage({
        urls: arr,
      });
    },
    changesw(e) {
      console.log(e);
      this.tabCurrent = e.detail.current;
    },
    //更新图片地址
    updateUrlList(list, type) {
      console.log("list", list, type);
      // let formList = ['chukou', 'chongxi', 'fangchen', 'dibang', 'shipin', 'qita']
      let formList = ["chukou", "chongxi", "fangchen", "shipin", "qita"];
      this.form[formList[type]] = list;
      console.log(this.form);
    },
    upchange(a, b, c) {
      console.log("change错误", a, b, c);
    },
    uppross(a, b, c) {
      console.log("pross错误", a, b, c);
    },
    uperror(a, b, c) {
      console.log("上传错误", a, b, c);
    },
    //分派关闭工单
    allocateout() {
      if (this.outorder != 0) {
        uni.showModal({
          title: "提示",
          content: "是否确定提交？",
          confirmText: "确定",
          cancelText: "取消",
          success: (res) => {
            if (res.confirm) {
              if (this.outorder == 1) {
                allocatepostCloseOrder({
                  id: this.id,
                  other: {
                    result: "关闭",
                    content: this.type_value,
                  },
                })
                  .then((d) => {
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: "关闭成功",
                        type: "success",
                        url: "/pages/index/approval/index",
                      },
                      500
                    );
                  })
                  .catch((res) => {
                    console.log(res);
                    console.log(res.data.msg);
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: res.data.msg,
                        type: "warning",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );
                  });
              } else if (this.outorder == 2) {
                allocatepostWithdraw({
                  id: this.id,
                  other: {
                    result: "退单整改",
                    content: this.type_value,
                  },
                })
                  .then((res) => {
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: "退单成功",
                        type: "success",
                        url: "/pages/index/approval/index",
                      },
                      500
                    );
                    // uni.navigateBack()
                  })
                  .catch((res) => {
                    console.log(res);
                    console.log(res.data.msg);
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: res.data.msg,
                        type: "warning",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );
                  });
              } else {
                postBackStep({
                  id: this.id,
                  other: {
                    result: "返回上一节点",
                    content: this.type_value,
                  },
                })
                  .then((res) => {
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: "返回上一节点成功",
                        type: "success",
                        url: "/pages/index/approval/index",
                      },
                      500
                    );
                  })
                  .catch((res) => {
                    console.log(res);
                    console.log(res.data.msg);
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: res.data.msg,
                        type: "warning",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );
                  });
              }
            }
          },
        });
      }
    },
    tabChange(index) {
      this.tabCurrent = index;
    },
    //取消认领
    canceltake() {
      uni.showModal({
        title: "提示",
        content: "是否确定取消认领？",
        confirmText: "确定",
        cancelText: "取消",
        success: (res) => {
          if (res.confirm) {
            cancelTask({
              id: this.id,
            })
              .then((res) => {
                this.orderType = 0;
                this.checkop = -1;
                // this.stepsnumber = (this.buttontype == 1 ? 0 : 3)
                if (this.buttontype == 1) {
                  //重置四至范围
                  this.$store.state.path = 1;
                  this.$store.state.center = [];
                }
              })
              .catch((res) => {
                console.log(res);
                console.log(res.data.msg);
                uni.$emit("updatelist", 10);
                this.$refs.uToast.show(
                  {
                    title: res.data.msg,
                    type: "warning",
                    url: "/pages/index/approval/index",
                  },
                  300
                );
              });
          }
        },
      });
    },
    //更新申报表
    updatechutumsg() {
      let params = {
        accessRoadSclerosis: this.form.chukou.join(","),
        flushingEquipment: this.form.chongxi.join(","),
        dustControl: this.form.fangchen.join(","),
        videoSurveillance: this.form.shipin.join(","),
        // weighbridge: this.form.dibang.join(','),
        other: this.form.qita.join(","),
        loessEarthQuantity:
          this.detailmsg.loessEarthQuantity1 +
          "," +
          this.detailmsg.loessEarthQuantity2,
        plantingSoilEarthQuantity:
          this.detailmsg.plantingSoilEarthQuantity1 +
          "," +
          this.detailmsg.plantingSoilEarthQuantity2,
        muckEarthQuantity:
          this.detailmsg.muckEarthQuantity1 +
          "," +
          this.detailmsg.muckEarthQuantity2,
        slurryEarthQuantity:
          this.detailmsg.slurryEarthQuantity1 +
          "," +
          this.detailmsg.slurryEarthQuantity2,
        wasterEarthQuantity:
          this.detailmsg.wasterEarthQuantity1 +
          "," +
          this.detailmsg.wasterEarthQuantity2,
        dangEarthQuantity:
          this.detailmsg.dangEarthQuantity1 +
          "," +
          this.detailmsg.dangEarthQuantity2,
        otherEarthQuantity:
          this.detailmsg.otherEarthQuantity1 +
          "," +
          this.detailmsg.otherEarthQuantity2,
        allEarthQuantity:
          this.detailmsg.allEarthQuantity1 +
          "," +
          this.detailmsg.allEarthQuantity2,
        competentDepartment: this.detailmsg.competentDepartment,
        fourAreaCenterPoint: this.$store.state.center.toString(),
        endTime: this.time1,
        startTime: this.time,
        id: this.detailmsg.id,
        isPromise: 1,
        fourArea: this.$store.state.path.toString(),
        fourAreaCenterSize: this.$store.state.polygonArea,
        siteName: this.detailmsg.siteName,
      };
      console.log("出土项目范围参数：", this.$store.state.path.toString());
      updatechutu(params)
        .then((res) => {
          console.log(res);
          this.$refs.uToast.show(
            {
              title: "提交成功",
              type: "success",
            },
            300
          );
        })
        .catch((e) => {
          // console.log(e.response.data.msg)
        });
    },
    //通过审核
    approved() {
      if (this.buttontype == 1) {
        if (this.$store.state.path == 1) {
          this.$toast("请选择四至范围");
          return;
        }
        if (
          this.redshow1 &&
          this.redshow2 &&
          this.redshow3 &&
          this.redshow4 &&
          this.redshow5 &&
          this.redshow6 &&
          this.redshow7
        ) {
          this.$toast("请填写正确的出土量");
          return;
        }
      }
      this.showPass = true;
    },
    onSure() {
      console.log(this.buttontype);
      switch (this.buttontype) {
        case "1":
          this.passin();
          break;
        case "3":
          this.comfirm(true);
          break;
        case "11":
          this.comfirm_part();
          break;
        default:
      }
    },
    //通过审核跳转
    passin() {
      // console.log(this.checkop, 77777)
      if (this.checkop == 2) {
        // console.log("审核跳转" + this.checkop, 77777)
        uni.showModal({
          title: "提示",
          content: "是否确定提交审核？",
          confirmText: "确定",
          cancelText: "取消",
          success: (res) => {
            if (res.confirm) {
              postCheck({
                id: this.id,
                other: {
                  result: "工单核验",
                  content: this.pass_value,
                },
              })
                .then((res) => {
                  this.show = false;
                  this.showPass = false;
                  this.$refs.uToast.show(
                    {
                      title: "审核成功",
                      type: "success",
                    },
                    300
                  );
                  uni.$emit("updatelist", 10);
                  // uni.navigateTo({
                  // 	url: '/pages/index/approval/chutu/passin'
                  // })
                  uni.navigateTo({
                    url: "/pages/index/approval/index",
                  });
                  console.log(res);
                })
                .catch((res) => {
                  console.log(res);
                  console.log(res.data.msg);
                  uni.$emit("updatelist", 10);
                  this.$refs.uToast.show(
                    {
                      title: res.data.msg,
                      type: "warning",
                      url: "/pages/index/approval/index",
                    },
                    300
                  );
                });
            }
          },
        });
      } else {
        // if (!this.redshow1 && !this.redshow2 && !this.redshow3 && !this.redshow4 && !this.redshow5 && !this
        // 	.redshow6 && !this.redshow7) {
        // 	console.log('总量', this.detailmsg.allEarthQuantity)
        // 	if (this.detailmsg.allEarthQuantity1 >= 0 && this.detailmsg.allEarthQuantity2 >= 0) {

        // 	} else {
        // 		this.$refs.uToast.show({
        // 			title: '请完整填写出土量',
        // 			type: 'warning'
        // 		}, 300)
        // 	}

        // } else {
        // 	this.$refs.uToast.show({
        // 		title: '请正确填写出土量或框选四至范围',
        // 		type: 'warning'
        // 	}, 300)
        // }
        uni.showModal({
          title: "提示",
          content: "是否确定提交审核？",
          confirmText: "确定",
          cancelText: "取消",
          success: (res) => {
            if (res.confirm) {
              postCheck({
                id: this.id,
                other: {
                  result: "工单核验",
                  content: this.pass_value,
                },
              })
                .then((res) => {
                  this.show = false;
                  this.showPass = false;
                  this.buttontype = 10;
                  this.updatechutumsg();
                  setTimeout(() => {
                    let params = {
                      // isDelay: this.isDelay,
                      size: 1000,
                      itemId: "402887ae7b62cd4f017b62ef1f4c0170",
                    };
                    getMyList(params).then((res) => {
                      res.rows.forEach((d) => {
                        if (d.id == this.idd) {
                          this.id = d.recordId;
                          this.nodeId = d.nodeId;
                          this.getolddetail(); //刷新整条工单
                          this.checkop = -1;
                        }
                      });
                    });
                  }, 300);
                })
                .catch((res) => {
                  console.log(res);
                  console.log(res.data.msg);
                  uni.$emit("updatelist", 10);
                  this.$refs.uToast.show(
                    {
                      title: res.data.msg,
                      type: "warning",
                      url: "/pages/index/approval/index",
                    },
                    300
                  );
                });
            }
          },
        });
      }
    },
    //获取分配部门
    getorgByNodeId() {
      this.list = [];
      orgByNodeId({
        nodeId: this.nodeId,
      }).then((res) => {
        console.log(res, "----------------res");
        res.forEach((d) => {
          this.list.push({
            nodeId: d.nodeId,
            orgId: d.orgId,
            orgName: d.orgName,
            checked: false,
            disabled: false,
          });
        });

        this.list.forEach((item, index) => {
          // 去除括号及内容
          item.orgName = item.orgName.replace(/\（.*?\）/g, "");
        });
        console.log(this.list, "eeeeeeeeeeeeeeeeeeethis.list");
        // 默认选中字段
        this.list.forEach((item, index) => {
          if (this.detailmsg.competentDepartment == item.orgName) {
            item.checked = true;
          } else if (this.detailmsg.street == item.orgName) {
            item.checked = true;
          }
        });

        this.list.forEach((item, index) => {
          if (item.checked == true) {
            this.activelist.push(item.orgId);
            this.activeOrgName.push(item.orgName);
          }
        });

        console.log(res, 9999999, this.nodeId);
        console.log(res, 9999999, this.list);
      });
    },
    getolddetail() {
      return new Promise((resolve, reject) => {
        getByOrdersId({
          ordersId: this.idd,
        })
          .then((res) => {
            let str = "350821 1998041349 17";
            console.log(res, 333);
            this.detailmsg = res;
            this.setInfoApprove(this.detailmsg);
            if (res) {
              //身份证打码
              this.detailmsg.reportPersonIdcard =
                this.detailmsg.reportPersonIdcard.slice(0, 6) +
                "**********" +
                this.detailmsg.reportPersonIdcard.slice(16, 18);
              this.detailmsg.loessEarthQuantity1 =
                this.detailmsg.loessEarthQuantity.split(",")[0];
              this.detailmsg.loessEarthQuantity2 =
                this.detailmsg.loessEarthQuantity.split(",")[1];
              this.detailmsg.plantingSoilEarthQuantity1 =
                this.detailmsg.plantingSoilEarthQuantity.split(",")[0];
              this.detailmsg.plantingSoilEarthQuantity2 =
                this.detailmsg.plantingSoilEarthQuantity.split(",")[1];
              this.detailmsg.muckEarthQuantity1 =
                this.detailmsg.muckEarthQuantity.split(",")[0];
              this.detailmsg.muckEarthQuantity2 =
                this.detailmsg.muckEarthQuantity.split(",")[1];
              this.detailmsg.slurryEarthQuantity1 =
                this.detailmsg.slurryEarthQuantity.split(",")[0];
              this.detailmsg.slurryEarthQuantity2 =
                this.detailmsg.slurryEarthQuantity.split(",")[1];
              this.detailmsg.wasterEarthQuantity1 =
                this.detailmsg.wasterEarthQuantity.split(",")[0];
              this.detailmsg.wasterEarthQuantity2 =
                this.detailmsg.wasterEarthQuantity.split(",")[1];
              this.detailmsg.otherEarthQuantity1 =
                this.detailmsg.otherEarthQuantity.split(",")[0];
              this.detailmsg.otherEarthQuantity2 =
                this.detailmsg.otherEarthQuantity.split(",")[1];
              this.detailmsg.allEarthQuantity1 =
                this.detailmsg.allEarthQuantity.split(",")[0];
              this.detailmsg.allEarthQuantity2 =
                this.detailmsg.allEarthQuantity.split(",")[1];
              this.detailmsg.dangEarthQuantity1 =
                this.detailmsg.dangEarthQuantity.split(",")[0];
              this.detailmsg.dangEarthQuantity2 =
                this.detailmsg.dangEarthQuantity.split(",")[1];
              this.time = this.detailmsg.startTime;
              this.time1 = this.detailmsg.endTime;
              console.log(this.detailmsg.accessRoadSclerosis);

              this.detailmsg.tenderList =
                this.detailmsg.tenderList.split(",") || "";
              this.detailmsg.ownerCompany.businessLicense =
                this.detailmsg.ownerCompany.businessLicense.split(",") || "";
              this.detailmsg.constructionCompany.businessLicense =
                this.detailmsg.constructionCompany.businessLicense.split(",");
              this.detailmsg.buildCompany.businessLicense =
                this.detailmsg.buildCompany.businessLicense.split(",");
              this.detailmsg.constructionCompany.relatedContracts =
                this.detailmsg.constructionCompany.relatedContracts.split(",");
              //出口道路硬化
              if (
                this.detailmsg.accessRoadSclerosis == null ||
                this.detailmsg.accessRoadSclerosis == ""
              ) {
                this.detailmsg.accessRoadSclerosis = [];
                this.form.chukou = [];
              } else {
                this.form.chukou =
                  this.detailmsg.accessRoadSclerosis.split(",");
                this.detailmsg.accessRoadSclerosis =
                  this.detailmsg.accessRoadSclerosis.split(",");
              }
              //冲洗设备
              if (
                this.detailmsg.flushingEquipment == null ||
                this.detailmsg.flushingEquipment == ""
              ) {
                this.form.chongxi = [];
                this.detailmsg.flushingEquipment = [];
              } else {
                this.form.chongxi = this.detailmsg.flushingEquipment.split(",");
                this.detailmsg.flushingEquipment =
                  this.detailmsg.flushingEquipment.split(",");
              }
              //防尘降尘
              if (
                this.detailmsg.dustControl == null ||
                this.detailmsg.dustControl == ""
              ) {
                this.form.fangchen = [];
                this.detailmsg.dustControl = [];
              } else {
                this.form.fangchen = this.detailmsg.dustControl.split(",");
                this.detailmsg.dustControl =
                  this.detailmsg.dustControl.split(",");
              }
              //地磅
              // if (this.detailmsg.weighbridge == null || this.detailmsg.weighbridge == '') {
              // 	this.detailmsg.weighbridge = []
              // 	this.form.dibang = []
              // } else {
              // 	this.form.dibang = this.detailmsg.weighbridge.split(',')
              // 	this.detailmsg.weighbridge = this.detailmsg.weighbridge.split(',')
              // }
              //视频
              if (
                this.detailmsg.videoSurveillance == null ||
                this.detailmsg.videoSurveillance == ""
              ) {
                this.detailmsg.videoSurveillance = [];
                this.form.shipin = [];
              } else {
                this.form.shipin = this.detailmsg.videoSurveillance.split(",");
                this.detailmsg.videoSurveillance =
                  this.detailmsg.videoSurveillance.split(",");
              }

              if (
                this.detailmsg.soilMonitoring == null ||
                this.detailmsg.soilMonitoring == ""
              ) {
                this.detailmsg.soilMonitoring = [];
                this.form.shipin = [];
              } else {
                this.form.shipin = this.detailmsg.soilMonitoring.split(",");
                this.detailmsg.soilMonitoring =
                  this.detailmsg.soilMonitoring.split(",");
              }

              //其他
              if (this.detailmsg.other == null || this.detailmsg.other == "") {
                this.detailmsg.other = [];
                this.form.qita = [];
              } else {
                this.form.qita = this.detailmsg.other.split(","); //此处对form图片做数据回填--未操作图片也可直接提交到下一流程
                this.detailmsg.other = this.detailmsg.other.split(",");

                console.log(this.detailmsg.other);
              }
              // 图片显示操作
              this.nameList.forEach((item, index) => {
                console.log(this.detailmsg[item.id]);
                item.picList = this.detailmsg[item.id];
              });

              console.log("222222222出土照片", this.detailmsg);

              console.log("this.nameList", this.nameList);

              this.$store.state.path = 1;
              this.$store.state.center = [];
              // 四至范围坐标点解析
              if (this.detailmsg.fourArea) {
                this.$store.state.path = this.detailmsg.fourArea.split(",");
                this.detailmsg.fourArea = this.detailmsg.fourArea.split(",");

                this.polygons = this.initMapData(this.detailmsg.fourArea);
              }
              if (this.detailmsg.fourAreaCenterPoint) {
                let pattern =
                  /[`~!@#$^\-&*()=|{}':;'\\\[\]\<>\/?~！@#￥……&*（）——|{}【】'；：""'。，、？\s]/g;
                this.detailmsg.fourAreaCenterPoint =
                  this.detailmsg.fourAreaCenterPoint.replace(pattern, "");
                this.$store.state.center =
                  this.detailmsg.fourAreaCenterPoint.split(",");
                this.center = this.detailmsg.fourAreaCenterPoint.split(",");
                console.log(
                  this.center,
                  "this.centerthis.centerthis.centerthis.center"
                );
              }
              this.mapArea = this.detailmsg.fourAreaCenterSize;
              // reflag ? this.getorgByNodeId() : ''
              this.getorgByNodeId();
              this.getphotolist = this.detailmsg.accessRoadSclerosis.concat(
                this.detailmsg.tenderList,
                this.detailmsg.flushingEquipment,
                this.detailmsg.dustControl,
                this.detailmsg.weighbridge,
                this.detailmsg.videoSurveillance,
                this.detailmsg.other
              );
            }

            resolve(res);
          })
          .catch((err) => {
            reject(err);
          });
      });
    },
    // 地图四至范围数据处理
    initMapData(path) {
      let outArr = [];
      let lngArr = [];
      let latArr = [];
      let outArray2 = [];
      path.forEach((item, index) => {
        item = item.toString();
        let pattern =
          /[`~!@#$^\-&*()=|{}':;',\\\[\]\<>\/?~！@#￥……&*（）——|{}【】'；：""'。，、？\s]/g;
        item = item.replace(pattern, "");
        item = Number(item);
        if ((index + 1) % 2 == 0) {
          lngArr.push(item);
        } else {
          latArr.push(item);
        }
      });
      lngArr.forEach((item1, index1) => {
        outArr.push([latArr[index1], lngArr[index1]]);
      });
      outArr.forEach((item, index) => {
        outArray2.push({
          longitude: item[0],
          latitude: item[1],
        });
      });
      console.log(outArr, outArray2, "outArray");
      let polygons = [
        {
          // strokeColor: '#ff33ff80',
          strokeColor: "#FF33FF",
          strokeOpacity: 0.5,
          strokeWeight: 6,
          fillColor: "#1791fc80",
          points: outArray2,
        },
      ];
      console.log(polygons, "this.polygons,this.polygons");
      return polygons;
    },
    getdetail() {
      return new Promise((resolve, reject) => {
        getOrderDetail({
          id: this.id,
        })
          .then((res) => {
            console.log(res);
            this.detailList = res;
            this.setInfoOrder(this.detailList);
            this.orderType = this.detailList.orderType;
            this.buttontype = this.detailList.type;
            resolve(res);
          })
          .catch((err) => {
            reject(err);
          });
      });
    },
    //确认审核
    comfirm(flag) {
      if (this.outorder != 0 && !flag) {
        uni.showModal({
          title: "提示",
          content: "是否确定提交审核？",
          confirmText: "确定",
          cancelText: "取消",
          success: (res) => {
            if (res.confirm) {
              if (this.outorder == 1) {
                postCloseOrder({
                  id: this.id,
                  other: {
                    result: "关闭",
                    content: this.type_value,
                  },
                })
                  .then((d) => {
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: "关闭成功",
                        type: "success",
                        url: "/pages/index/approval/index",
                      },
                      500
                    );
                  })
                  .catch((res) => {
                    console.log(res);
                    console.log(res.data.msg);
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: res.data.msg,
                        type: "warning",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );
                  });
              } else if (this.outorder == 2) {
                postWithdraw({
                  id: this.id,
                  other: {
                    result: "退单整改",
                    content: this.type_value,
                  },
                })
                  .then((res) => {
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: "退单成功",
                        type: "success",
                        url: "/pages/index/approval/index",
                      },
                      500
                    );
                    // uni.navigateBack()
                  })
                  .catch((res) => {
                    console.log(res);
                    console.log(res.data.msg);
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: res.data.msg,
                        type: "warning",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );
                  });
              } else if (this.outorder == 3) {
                //通过
              } else {
                postBackStep({
                  id: this.id,
                  other: {
                    result: "返回上一节点",
                    content: this.type_value,
                  },
                })
                  .then((res) => {
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: "返回上一节点成功",
                        type: "success",
                        url: "/pages/index/approval/index",
                      },
                      500
                    );
                  })
                  .catch((res) => {
                    console.log(res);
                    console.log(res.data.msg);
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: res.data.msg,
                        type: "warning",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );
                  });
              }
            }
          },
        });
      } else {
        if (this.buttontype == 2) {
          uni.showModal({
            title: "提示",
            content: "是否确定提交？",
            confirmText: "确定",
            cancelText: "取消",
            success: (res) => {
              if (res.confirm) {
                postOrderHandle({
                  id: this.id,
                  other: {
                    result: "工单处置",
                    content: this.type_value,
                  },
                })
                  .then((res) => {
                    this.getdetail();
                    this.show = false;
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: "审核成功",
                        type: "success",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );
                    // uni.navigateBack()
                  })
                  .catch((res) => {
                    console.log(res);
                    console.log(res.data.msg);
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: res.data.msg,
                        type: "warning",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );
                  });
              }
            },
          });
        } else if (this.buttontype == 3) {
          uni.showModal({
            title: "提示",
            content: "是否确定提交审核？",
            confirmText: "确定",
            cancelText: "取消",
            success: (res) => {
              if (res.confirm) {
                postOrderAudit({
                  id: this.id,
                  other: {
                    result: "工单审核",
                    content: this.pass_value,
                  },
                })
                  .then((res) => {
                    this.show = false;
                    this.showPass = false;
                    //重新获取完成任务的recordId
                    setTimeout(() => {
                      let params = {
                        // isDelay: this.isDelay,
                        size: 1000,
                        itemId: "402887ae7b62cd4f017b62ef1f4c0170",
                      };
                      getMyList(params).then((res) => {
                        res.rows.forEach((d) => {
                          if (d.id == this.idd) {
                            this.id = d.recordId;
                            this.nodeId = d.nodeId;
                            this.checkop = -1;
                          }
                        });
                        this.getcircul();
                        console.log("流转记录", this.circulList);
                        this.orderFinishHandle();
                      });
                    }, 100);

                    // uni.navigateBack()
                    console.log(res);
                  })
                  .catch((res) => {
                    console.log(res);
                    console.log(res.data.msg);
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: res.data.msg,
                        type: "warning",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );
                  });
              }
            },
          });
        }
      }
    },
    //工单流记录
    getcircul() {
      getWorkOrderLogs({
        id: this.idd,
      }).then((res) => {
        console.log("************************", res);
        this.circulList = res;
        this.setInfoRecords(this.circulList);
      });
    },
    // 跳转至表单盖章页面pages/webview/finnish
    orderFinishHandle() {
      console.log(this.detailmsg);
      this.setInfoApprove(this.detailmsg);
      this.setInfoOrder(this.detailList);
      this.setInfoRecords(this.circulList);
      uni.navigateTo({
        url: `/pages/webview/finnish?type=2`,
      });
    },
    //任务认领
    taketask() {
      uni.showModal({
        title: "提示",
        content: "是否确定认领？",
        confirmText: "确定",
        cancelText: "取消",
        success: (res) => {
          if (res.confirm) {
            getTakeTask({
              id: this.id,
            })
              .then((res) => {
                this.orderType = 1;
                console.log(
                  this.stepsnumber,
                  "this.stepsnumberthis.stepsnumber"
                );
                if (this.stepsnumber == 1) {
                  this.checkop = 1;
                }
                console.log(res);
              })
              .catch((res) => {
                console.log(res);
                console.log(res.data.msg);
                uni.$emit("updatelist", 10);
                this.$refs.uToast.show(
                  {
                    title: res.data.msg,
                    type: "warning",
                    url: "/pages/index/approval/index",
                  },
                  300
                );
              });
          }
        },
      });
    },

    // 选中某个复选框时，由checkbox时触发
    checkboxChange(e) {
      console.log(e);
      let index = this.activelist.indexOf(e.name[0]);
      let num = this.activeOrgName.indexOf(e.name[1]);
      if (index > -1) {
        this.activelist.splice(index, 1);
      } else {
        this.activelist.push(e.name[0]);
      }
      if (num > -1) {
        this.activeOrgName.splice(num, 1);
      } else {
        this.activeOrgName.push(e.name[1]);
      }
      console.log(this.activeOrgName, this.activelist);
    },
    // 全选
    checkedAll() {
      this.list.map((val) => {
        val.checked = true;
      });
    },
    //不通过，退单整改
    passout(index) {
      this.show = true;
      this.outorder = index;
    },
    comfirm_part() {
      uni.showModal({
        title: "提示",
        content: "是否确定提交？",
        confirmText: "确定",
        cancelText: "取消",
        success: (res) => {
          if (res.confirm) {
            if (this.buttontype == 11) {
              allocatedo({
                id: this.id,
                formValue: [
                  {
                    name: "orderName",
                    type: "text",
                    params: {},
                    display_name: "分派处置内容",
                    orderName: "审核通过",
                  },
                ],
                other: {
                  result: "部门审核通过",
                  content: this.pass_value,
                },
              })
                .then((d) => {
                  console.log(d);

                  this.show = false;
                  this.showPass = false;
                  uni.$emit("updatelist", 10);
                  this.$refs.uToast.show(
                    {
                      title: "提交成功",
                      type: "success",
                      url: "/pages/index/approval/index",
                    },
                    500
                  );
                  // uni.navigateBack()
                })
                .catch((res) => {
                  console.log(res);
                  console.log(res.data.msg);
                  uni.$emit("updatelist", 10);
                  this.$refs.uToast.show(
                    {
                      title: res.data.msg,
                      type: "warning",
                      url: "/pages/index/approval/index",
                    },
                    300
                  );
                });
            } else {
              // this.activelist = ['GO_df2f46315d414518a31bea909fbd67a6']
              console.log(this.activelist);
              if (this.activelist.length == 0) {
                this.$refs.uToast.show(
                  {
                    title: "请选择的分派部门",
                    type: "warning",
                  },
                  500
                );
              } else {
                allocate({
                  id: this.id,
                  orgIds: this.activelist,
                  other: {
                    result: "工单分配",
                    content: "工单分配",
                    orgName: this.activeOrgName,
                  },
                })
                  .then((res) => {
                    this.show = false;
                    uni.$emit("updatelist", 10);
                    // uni.navigateBack()
                    this.$refs.uToast.show(
                      {
                        title: "提交成功",
                        type: "success",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );

                    console.log(res);
                  })
                  .catch((res) => {
                    console.log(res);
                    console.log(res.data.msg);
                    uni.$emit("updatelist", 10);
                    this.$refs.uToast.show(
                      {
                        title: res.data.msg,
                        type: "warning",
                        url: "/pages/index/approval/index",
                      },
                      300
                    );
                  });
              }
            }
          }
        },
      });
    },
    getDate(type) {
      const date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      if (type === "start") {
        year = year - 60;
      } else if (type === "end") {
        year = year + 2;
      }
      month = month > 9 ? month : "0" + month;
      day = day > 9 ? day : "0" + day;
      return `${year}-${month}-${day}`;
    },
    navigationToEvent() {
      console.log(this.detailmsg.fourArea, "this.detailList.fourArea");
      console.log("this.checkop", this.checkop);
      if (this.checkop == 1) {
        // uni.navigateTo({
        // 	url: `/pages/drawmap/index?&lat=${this.detailmsg.lat}&lng=${this.detailmsg.lng}`
        // })
        if (this.$store.state.path == 1) {
          //未绘制
          uni.navigateTo({
            url: `/pages/drawmap/index?&lat=${this.detailmsg.lat}&lng=${this.detailmsg.lng}`,
          });
        } else {
          uni.navigateTo({
            url: `/pages/drawmap/index?&lat=${this.detailmsg.lat}&lng=${
              this.detailmsg.lng
            }&fourArea=${this.$store.state.path.toString()}`,
          });
        }
      } else {
        // uni.navigateTo({
        // 	url: `/pages/drawmap/index?&lat=${this.detailmsg.lat}&lng=${this.detailmsg.lng}&fourArea=${this.detailmsg.fourArea}&type=check`
        // })
      }
    },
    //返回上一级
    goBack() {
      uni.navigateBack();
    },
    //获取当前位置
    getLocation() {
      uni.getLocation({
        type: "wgs84",
        geocode: true,
        success: (res) => {
          console.log(res, 888);
          this.form.lat = res.latitude;
          this.form.lng = res.longitude;
          this.getaddress(this.form.lng, this.form.lat);
        },
      });
    },
    //重新定位
    rePostioning() {
      uni.showLoading({
        title: "正在获取当前位置",
      });
      setTimeout(() => {
        this.getLocation();
      }, 800);
    },

    uperr(a, b, c) {
      console.log(a, b, c);
    },
    getaddress(lat, lon) {
      this.test.getRegeo({
        location: lat + "," + lon, //location的格式为'经度,纬度'
        //成功回调
        success: (data) => {
          console.log(data[0].regeocodeData.formatted_address, data[0].name);
          this.form.address = data[0].regeocodeData.formatted_address;
        },
        fail: function (info) {
          //失败回调
          console.log(info);
        },
      });
    },
    inputs(e) {
      let val = 0;
      this.detailmsg.muckEarthQuantity1 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity1) +
        parseInt(this.detailmsg.loessEarthQuantity1) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity1) +
        parseInt(this.detailmsg.slurryEarthQuantity1) +
        parseInt(this.detailmsg.wasterEarthQuantity1) +
        parseInt(this.detailmsg.otherEarthQuantity1) +
        parseInt(this.detailmsg.dangEarthQuantity1);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity1: val,
      });
      if (
        parseInt(this.detailmsg.muckEarthQuantity1) <
        parseInt(this.detailmsg.muckEarthQuantity2)
      ) {
        this.redshow1 = true;
      } else {
        this.redshow1 = false;
      }
      console.log(
        this.detailmsg.muckEarthQuantity1,
        this.detailmsg.allEarthQuantity1
      );
    },
    input_year(e) {
      let val = 0;
      this.detailmsg.muckEarthQuantity2 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity2) +
        parseInt(this.detailmsg.loessEarthQuantity2) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity2) +
        parseInt(this.detailmsg.slurryEarthQuantity2) +
        parseInt(this.detailmsg.wasterEarthQuantity2) +
        parseInt(this.detailmsg.otherEarthQuantity2) +
        parseInt(this.detailmsg.dangEarthQuantity2);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity2: val,
      });
      if (
        parseInt(this.detailmsg.muckEarthQuantity1) <
        parseInt(this.detailmsg.muckEarthQuantity2)
      ) {
        this.redshow1 = true;
      } else {
        this.redshow1 = false;
      }
    },
    inputs1(e) {
      let val = 0;
      this.detailmsg.loessEarthQuantity1 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity1) +
        parseInt(this.detailmsg.loessEarthQuantity1) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity1) +
        parseInt(this.detailmsg.slurryEarthQuantity1) +
        parseInt(this.detailmsg.wasterEarthQuantity1) +
        parseInt(this.detailmsg.otherEarthQuantity1) +
        parseInt(this.detailmsg.dangEarthQuantity1);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity1: val,
      });
      if (
        parseInt(this.detailmsg.loessEarthQuantity1) <
        parseInt(this.detailmsg.loessEarthQuantity2)
      ) {
        this.redshow2 = true;
      } else {
        this.redshow2 = false;
      }
    },
    input_year1(e) {
      let val = 0;
      this.detailmsg.loessEarthQuantity2 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity2) +
        parseInt(this.detailmsg.loessEarthQuantity2) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity2) +
        parseInt(this.detailmsg.slurryEarthQuantity2) +
        parseInt(this.detailmsg.wasterEarthQuantity2) +
        parseInt(this.detailmsg.otherEarthQuantity2) +
        parseInt(this.detailmsg.dangEarthQuantity2);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity2: val,
      });
      if (
        parseInt(this.detailmsg.loessEarthQuantity1) <
        parseInt(this.detailmsg.loessEarthQuantity2)
      ) {
        this.redshow2 = true;
      } else {
        this.redshow2 = false;
      }
      console.log(
        this.detailmsg.muckEarthQuantity2,
        this.detailmsg.allEarthQuantity2
      );
    },
    inputs2(e) {
      let val = 0;
      this.detailmsg.plantingSoilEarthQuantity1 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity1) +
        parseInt(this.detailmsg.loessEarthQuantity1) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity1) +
        parseInt(this.detailmsg.slurryEarthQuantity1) +
        parseInt(this.detailmsg.wasterEarthQuantity1) +
        parseInt(this.detailmsg.otherEarthQuantity1) +
        parseInt(this.detailmsg.dangEarthQuantity1);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity1: val,
      });
      if (
        parseInt(this.detailmsg.plantingSoilEarthQuantity1) <
        parseInt(this.detailmsg.plantingSoilEarthQuantity2)
      ) {
        this.redshow3 = true;
      } else {
        this.redshow3 = false;
      }
    },
    input_year2(e) {
      let val = 0;
      this.detailmsg.plantingSoilEarthQuantity2 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity2) +
        parseInt(this.detailmsg.loessEarthQuantity2) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity2) +
        parseInt(this.detailmsg.slurryEarthQuantity2) +
        parseInt(this.detailmsg.wasterEarthQuantity2) +
        parseInt(this.detailmsg.otherEarthQuantity2) +
        parseInt(this.detailmsg.dangEarthQuantity2);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity2: val,
      });
      if (
        parseInt(this.detailmsg.plantingSoilEarthQuantity1) <
        parseInt(this.detailmsg.plantingSoilEarthQuantity2)
      ) {
        this.redshow3 = true;
      } else {
        this.redshow3 = false;
      }
      console.log(
        this.detailmsg.muckEarthQuantity2,
        this.detailmsg.allEarthQuantity2
      );
    },
    inputs5(e) {
      let val = 0;
      this.detailmsg.otherEarthQuantity1 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity1) +
        parseInt(this.detailmsg.loessEarthQuantity1) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity1) +
        parseInt(this.detailmsg.slurryEarthQuantity1) +
        parseInt(this.detailmsg.wasterEarthQuantity1) +
        parseInt(this.detailmsg.otherEarthQuantity1) +
        parseInt(this.detailmsg.dangEarthQuantity1);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity1: val,
      });
      if (
        parseInt(this.detailmsg.otherEarthQuantity1) <
        parseInt(this.detailmsg.otherEarthQuantity2)
      ) {
        this.redshow6 = true;
      } else {
        this.redshow6 = false;
      }
    },
    input_year5(e) {
      let val = 0;
      this.detailmsg.otherEarthQuantity2 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity2) +
        parseInt(this.detailmsg.loessEarthQuantity2) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity2) +
        parseInt(this.detailmsg.slurryEarthQuantity2) +
        parseInt(this.detailmsg.wasterEarthQuantity2) +
        parseInt(this.detailmsg.otherEarthQuantity2) +
        parseInt(this.detailmsg.dangEarthQuantity2);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity2: val,
      });
      if (
        parseInt(this.detailmsg.otherEarthQuantity1) <
        parseInt(this.detailmsg.otherEarthQuantity2)
      ) {
        this.redshow6 = true;
      } else {
        this.redshow6 = false;
      }
      console.log(
        this.detailmsg.muckEarthQuantity2,
        this.detailmsg.allEarthQuantity2
      );
    },
    inputs7(e) {
      let val = 0;
      this.detailmsg.dangEarthQuantity1 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity1) +
        parseInt(this.detailmsg.loessEarthQuantity1) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity1) +
        parseInt(this.detailmsg.slurryEarthQuantity1) +
        parseInt(this.detailmsg.wasterEarthQuantity1) +
        parseInt(this.detailmsg.otherEarthQuantity1) +
        parseInt(this.detailmsg.dangEarthQuantity1);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity1: val,
      });
      if (
        parseInt(this.detailmsg.dangEarthQuantity1) <
        parseInt(this.detailmsg.dangEarthQuantity2)
      ) {
        this.redshow7 = true;
      } else {
        this.redshow7 = false;
      }
    },
    input_year7(e) {
      let val = 0;
      this.detailmsg.dangEarthQuantity2 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity2) +
        parseInt(this.detailmsg.loessEarthQuantity2) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity2) +
        parseInt(this.detailmsg.slurryEarthQuantity2) +
        parseInt(this.detailmsg.wasterEarthQuantity2) +
        parseInt(this.detailmsg.otherEarthQuantity2) +
        parseInt(this.detailmsg.dangEarthQuantity2);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity2: val,
      });
      if (
        parseInt(this.detailmsg.dangEarthQuantity1) <
        parseInt(this.detailmsg.dangEarthQuantity2)
      ) {
        this.redshow7 = true;
      } else {
        this.redshow7 = false;
      }
      console.log(
        this.detailmsg.muckEarthQuantity2,
        this.detailmsg.allEarthQuantity2
      );
    },
    inputs3(e) {
      let val = 0;
      this.detailmsg.slurryEarthQuantity1 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity1) +
        parseInt(this.detailmsg.loessEarthQuantity1) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity1) +
        parseInt(this.detailmsg.slurryEarthQuantity1) +
        parseInt(this.detailmsg.wasterEarthQuantity1) +
        parseInt(this.detailmsg.otherEarthQuantity1) +
        parseInt(this.detailmsg.dangEarthQuantity1);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity1: val,
      });
      if (
        parseInt(this.detailmsg.slurryEarthQuantity1) <
        parseInt(this.detailmsg.slurryEarthQuantity2)
      ) {
        this.redshow4 = true;
      } else {
        this.redshow4 = false;
      }
    },
    input_year3(e) {
      let val = 0;
      this.detailmsg.slurryEarthQuantity2 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity2) +
        parseInt(this.detailmsg.loessEarthQuantity2) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity2) +
        parseInt(this.detailmsg.slurryEarthQuantity2) +
        parseInt(this.detailmsg.wasterEarthQuantity2) +
        parseInt(this.detailmsg.otherEarthQuantity2) +
        parseInt(this.detailmsg.dangEarthQuantity2);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity2: val,
      });
      console.log(
        this.detailmsg.muckEarthQuantity2,
        this.detailmsg.allEarthQuantity2
      );
      if (
        parseInt(this.detailmsg.slurryEarthQuantity1) <
        parseInt(this.detailmsg.slurryEarthQuantity2)
      ) {
        this.redshow4 = true;
      } else {
        this.redshow4 = false;
      }
    },
    inputs4(e) {
      let val = 0;
      this.detailmsg.wasterEarthQuantity1 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity1) +
        parseInt(this.detailmsg.loessEarthQuantity1) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity1) +
        parseInt(this.detailmsg.slurryEarthQuantity1) +
        parseInt(this.detailmsg.wasterEarthQuantity1) +
        parseInt(this.detailmsg.otherEarthQuantity1) +
        parseInt(this.detailmsg.dangEarthQuantity1);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity1: val,
      });
      if (
        parseInt(this.detailmsg.wasterEarthQuantity1) <
        parseInt(this.detailmsg.wasterEarthQuantity2)
      ) {
        this.redshow5 = true;
      } else {
        this.redshow5 = false;
      }
    },
    input_year4(e) {
      let val = 0;
      this.detailmsg.wasterEarthQuantity2 = e.detail.value;
      val =
        parseInt(this.detailmsg.muckEarthQuantity2) +
        parseInt(this.detailmsg.loessEarthQuantity2) +
        parseInt(this.detailmsg.plantingSoilEarthQuantity2) +
        parseInt(this.detailmsg.slurryEarthQuantity2) +
        parseInt(this.detailmsg.wasterEarthQuantity2) +
        parseInt(this.detailmsg.otherEarthQuantity2) +
        parseInt(this.detailmsg.dangEarthQuantity2);
      this.detailmsg = Object.assign({}, this.detailmsg, {
        allEarthQuantity2: val,
      });
      if (
        parseInt(this.detailmsg.wasterEarthQuantity1) <
        parseInt(this.detailmsg.wasterEarthQuantity2)
      ) {
        this.redshow5 = true;
      } else {
        this.redshow5 = false;
      }
      console.log(
        this.detailmsg.muckEarthQuantity2,
        this.detailmsg.allEarthQuantity2
      );
    },
    inputsName(e) {
      let val = 0;
      this.detailmsg.siteName = e.detail.value;
    },
  },
};
